﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using NetROS.Tiers.Entities;
using NetROS.Tiers.Data;

#endregion

namespace NetROS.Tiers.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="VwOsobaProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class VwOsobaProviderBaseCore : EntityViewProviderBase<VwOsoba>
	{
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;VwOsoba&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;VwOsoba&gt;"/></returns>
		protected static VList&lt;VwOsoba&gt; Fill(DataSet dataSet, VList<VwOsoba> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<VwOsoba>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;VwOsoba&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<VwOsoba>"/></returns>
		protected static VList&lt;VwOsoba&gt; Fill(DataTable dataTable, VList<VwOsoba> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					VwOsoba c = new VwOsoba();
					c.ID = (Convert.IsDBNull(row["ID"]))?(int)0:(System.Int32)row["ID"];
					c.Prezime = (Convert.IsDBNull(row["Prezime"]))?string.Empty:(System.String)row["Prezime"];
					c.Ime = (Convert.IsDBNull(row["Ime"]))?string.Empty:(System.String)row["Ime"];
					c.MjesoRodenjaNaziv = (Convert.IsDBNull(row["MjesoRodenjaNaziv"]))?string.Empty:(System.String)row["MjesoRodenjaNaziv"];
					c.MBG = (Convert.IsDBNull(row["MBG"]))?string.Empty:(System.String)row["MBG"];
					c.OIB = (Convert.IsDBNull(row["OIB"]))?string.Empty:(System.String)row["OIB"];
					c.DatumRodenja = (Convert.IsDBNull(row["DatumRodenja"]))?DateTime.MinValue:(System.DateTime?)row["DatumRodenja"];
					c.Napomena = (Convert.IsDBNull(row["Napomena"]))?string.Empty:(System.String)row["Napomena"];
					c.OsobniOdbitak = (Convert.IsDBNull(row["OsobniOdbitak"]))?0.0F:(System.Single)row["OsobniOdbitak"];
					c.TrenutnoRadnoMjesto = (Convert.IsDBNull(row["TrenutnoRadnoMjesto"]))?string.Empty:(System.String)row["TrenutnoRadnoMjesto"];
					c.TrenutniRadniOdnosTip = (Convert.IsDBNull(row["TrenutniRadniOdnosTip"]))?string.Empty:(System.String)row["TrenutniRadniOdnosTip"];
					c.TrenutnoMjestoBoravista = (Convert.IsDBNull(row["TrenutnoMjestoBoravista"]))?string.Empty:(System.String)row["TrenutnoMjestoBoravista"];
					c.TrenutnaOrganizacijskaJedinica = (Convert.IsDBNull(row["TrenutnaOrganizacijskaJedinica"]))?string.Empty:(System.String)row["TrenutnaOrganizacijskaJedinica"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;VwOsoba&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;VwOsoba&gt;"/></returns>
		protected VList<VwOsoba> Fill(IDataReader reader, VList<VwOsoba> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					VwOsoba entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<VwOsoba>("VwOsoba",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new VwOsoba();
					}
					entity.ID = (System.Int32)reader["ID"];
					//entity.ID = (Convert.IsDBNull(reader["ID"]))?(int)0:(System.Int32)reader["ID"];
					entity.Prezime = (System.String)reader["Prezime"];
					//entity.Prezime = (Convert.IsDBNull(reader["Prezime"]))?string.Empty:(System.String)reader["Prezime"];
					entity.Ime = (System.String)reader["Ime"];
					//entity.Ime = (Convert.IsDBNull(reader["Ime"]))?string.Empty:(System.String)reader["Ime"];
					entity.MjesoRodenjaNaziv = (System.String)reader["MjesoRodenjaNaziv"];
					//entity.MjesoRodenjaNaziv = (Convert.IsDBNull(reader["MjesoRodenjaNaziv"]))?string.Empty:(System.String)reader["MjesoRodenjaNaziv"];
					entity.MBG = reader.IsDBNull(reader.GetOrdinal("MBG")) ? null : (System.String)reader["MBG"];
					//entity.MBG = (Convert.IsDBNull(reader["MBG"]))?string.Empty:(System.String)reader["MBG"];
					entity.OIB = reader.IsDBNull(reader.GetOrdinal("OIB")) ? null : (System.String)reader["OIB"];
					//entity.OIB = (Convert.IsDBNull(reader["OIB"]))?string.Empty:(System.String)reader["OIB"];
					entity.DatumRodenja = reader.IsDBNull(reader.GetOrdinal("DatumRodenja")) ? null : (System.DateTime?)reader["DatumRodenja"];
					//entity.DatumRodenja = (Convert.IsDBNull(reader["DatumRodenja"]))?DateTime.MinValue:(System.DateTime?)reader["DatumRodenja"];
					entity.Napomena = reader.IsDBNull(reader.GetOrdinal("Napomena")) ? null : (System.String)reader["Napomena"];
					//entity.Napomena = (Convert.IsDBNull(reader["Napomena"]))?string.Empty:(System.String)reader["Napomena"];
					entity.OsobniOdbitak = (System.Single)reader["OsobniOdbitak"];
					//entity.OsobniOdbitak = (Convert.IsDBNull(reader["OsobniOdbitak"]))?0.0F:(System.Single)reader["OsobniOdbitak"];
					entity.TrenutnoRadnoMjesto = reader.IsDBNull(reader.GetOrdinal("TrenutnoRadnoMjesto")) ? null : (System.String)reader["TrenutnoRadnoMjesto"];
					//entity.TrenutnoRadnoMjesto = (Convert.IsDBNull(reader["TrenutnoRadnoMjesto"]))?string.Empty:(System.String)reader["TrenutnoRadnoMjesto"];
					entity.TrenutniRadniOdnosTip = reader.IsDBNull(reader.GetOrdinal("TrenutniRadniOdnosTip")) ? null : (System.String)reader["TrenutniRadniOdnosTip"];
					//entity.TrenutniRadniOdnosTip = (Convert.IsDBNull(reader["TrenutniRadniOdnosTip"]))?string.Empty:(System.String)reader["TrenutniRadniOdnosTip"];
					entity.TrenutnoMjestoBoravista = reader.IsDBNull(reader.GetOrdinal("TrenutnoMjestoBoravista")) ? null : (System.String)reader["TrenutnoMjestoBoravista"];
					//entity.TrenutnoMjestoBoravista = (Convert.IsDBNull(reader["TrenutnoMjestoBoravista"]))?string.Empty:(System.String)reader["TrenutnoMjestoBoravista"];
					entity.TrenutnaOrganizacijskaJedinica = reader.IsDBNull(reader.GetOrdinal("TrenutnaOrganizacijskaJedinica")) ? null : (System.String)reader["TrenutnaOrganizacijskaJedinica"];
					//entity.TrenutnaOrganizacijskaJedinica = (Convert.IsDBNull(reader["TrenutnaOrganizacijskaJedinica"]))?string.Empty:(System.String)reader["TrenutnaOrganizacijskaJedinica"];
					entity.AcceptChanges();
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="VwOsoba"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="VwOsoba"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, VwOsoba entity)
		{
			reader.Read();
			entity.ID = (System.Int32)reader["ID"];
			//entity.ID = (Convert.IsDBNull(reader["ID"]))?(int)0:(System.Int32)reader["ID"];
			entity.Prezime = (System.String)reader["Prezime"];
			//entity.Prezime = (Convert.IsDBNull(reader["Prezime"]))?string.Empty:(System.String)reader["Prezime"];
			entity.Ime = (System.String)reader["Ime"];
			//entity.Ime = (Convert.IsDBNull(reader["Ime"]))?string.Empty:(System.String)reader["Ime"];
			entity.MjesoRodenjaNaziv = (System.String)reader["MjesoRodenjaNaziv"];
			//entity.MjesoRodenjaNaziv = (Convert.IsDBNull(reader["MjesoRodenjaNaziv"]))?string.Empty:(System.String)reader["MjesoRodenjaNaziv"];
			entity.MBG = reader.IsDBNull(reader.GetOrdinal("MBG")) ? null : (System.String)reader["MBG"];
			//entity.MBG = (Convert.IsDBNull(reader["MBG"]))?string.Empty:(System.String)reader["MBG"];
			entity.OIB = reader.IsDBNull(reader.GetOrdinal("OIB")) ? null : (System.String)reader["OIB"];
			//entity.OIB = (Convert.IsDBNull(reader["OIB"]))?string.Empty:(System.String)reader["OIB"];
			entity.DatumRodenja = reader.IsDBNull(reader.GetOrdinal("DatumRodenja")) ? null : (System.DateTime?)reader["DatumRodenja"];
			//entity.DatumRodenja = (Convert.IsDBNull(reader["DatumRodenja"]))?DateTime.MinValue:(System.DateTime?)reader["DatumRodenja"];
			entity.Napomena = reader.IsDBNull(reader.GetOrdinal("Napomena")) ? null : (System.String)reader["Napomena"];
			//entity.Napomena = (Convert.IsDBNull(reader["Napomena"]))?string.Empty:(System.String)reader["Napomena"];
			entity.OsobniOdbitak = (System.Single)reader["OsobniOdbitak"];
			//entity.OsobniOdbitak = (Convert.IsDBNull(reader["OsobniOdbitak"]))?0.0F:(System.Single)reader["OsobniOdbitak"];
			entity.TrenutnoRadnoMjesto = reader.IsDBNull(reader.GetOrdinal("TrenutnoRadnoMjesto")) ? null : (System.String)reader["TrenutnoRadnoMjesto"];
			//entity.TrenutnoRadnoMjesto = (Convert.IsDBNull(reader["TrenutnoRadnoMjesto"]))?string.Empty:(System.String)reader["TrenutnoRadnoMjesto"];
			entity.TrenutniRadniOdnosTip = reader.IsDBNull(reader.GetOrdinal("TrenutniRadniOdnosTip")) ? null : (System.String)reader["TrenutniRadniOdnosTip"];
			//entity.TrenutniRadniOdnosTip = (Convert.IsDBNull(reader["TrenutniRadniOdnosTip"]))?string.Empty:(System.String)reader["TrenutniRadniOdnosTip"];
			entity.TrenutnoMjestoBoravista = reader.IsDBNull(reader.GetOrdinal("TrenutnoMjestoBoravista")) ? null : (System.String)reader["TrenutnoMjestoBoravista"];
			//entity.TrenutnoMjestoBoravista = (Convert.IsDBNull(reader["TrenutnoMjestoBoravista"]))?string.Empty:(System.String)reader["TrenutnoMjestoBoravista"];
			entity.TrenutnaOrganizacijskaJedinica = reader.IsDBNull(reader.GetOrdinal("TrenutnaOrganizacijskaJedinica")) ? null : (System.String)reader["TrenutnaOrganizacijskaJedinica"];
			//entity.TrenutnaOrganizacijskaJedinica = (Convert.IsDBNull(reader["TrenutnaOrganizacijskaJedinica"]))?string.Empty:(System.String)reader["TrenutnaOrganizacijskaJedinica"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="VwOsoba"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="VwOsoba"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, VwOsoba entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.ID = (Convert.IsDBNull(dataRow["ID"]))?(int)0:(System.Int32)dataRow["ID"];
			entity.Prezime = (Convert.IsDBNull(dataRow["Prezime"]))?string.Empty:(System.String)dataRow["Prezime"];
			entity.Ime = (Convert.IsDBNull(dataRow["Ime"]))?string.Empty:(System.String)dataRow["Ime"];
			entity.MjesoRodenjaNaziv = (Convert.IsDBNull(dataRow["MjesoRodenjaNaziv"]))?string.Empty:(System.String)dataRow["MjesoRodenjaNaziv"];
			entity.MBG = (Convert.IsDBNull(dataRow["MBG"]))?string.Empty:(System.String)dataRow["MBG"];
			entity.OIB = (Convert.IsDBNull(dataRow["OIB"]))?string.Empty:(System.String)dataRow["OIB"];
			entity.DatumRodenja = (Convert.IsDBNull(dataRow["DatumRodenja"]))?DateTime.MinValue:(System.DateTime?)dataRow["DatumRodenja"];
			entity.Napomena = (Convert.IsDBNull(dataRow["Napomena"]))?string.Empty:(System.String)dataRow["Napomena"];
			entity.OsobniOdbitak = (Convert.IsDBNull(dataRow["OsobniOdbitak"]))?0.0F:(System.Single)dataRow["OsobniOdbitak"];
			entity.TrenutnoRadnoMjesto = (Convert.IsDBNull(dataRow["TrenutnoRadnoMjesto"]))?string.Empty:(System.String)dataRow["TrenutnoRadnoMjesto"];
			entity.TrenutniRadniOdnosTip = (Convert.IsDBNull(dataRow["TrenutniRadniOdnosTip"]))?string.Empty:(System.String)dataRow["TrenutniRadniOdnosTip"];
			entity.TrenutnoMjestoBoravista = (Convert.IsDBNull(dataRow["TrenutnoMjestoBoravista"]))?string.Empty:(System.String)dataRow["TrenutnoMjestoBoravista"];
			entity.TrenutnaOrganizacijskaJedinica = (Convert.IsDBNull(dataRow["TrenutnaOrganizacijskaJedinica"]))?string.Empty:(System.String)dataRow["TrenutnaOrganizacijskaJedinica"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region VwOsobaFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwOsoba"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwOsobaFilterBuilder : SqlFilterBuilder<VwOsobaColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwOsobaFilterBuilder class.
		/// </summary>
		public VwOsobaFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwOsobaFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwOsobaFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwOsobaFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwOsobaFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwOsobaFilterBuilder

	#region VwOsobaParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwOsoba"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwOsobaParameterBuilder : ParameterizedSqlFilterBuilder<VwOsobaColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwOsobaParameterBuilder class.
		/// </summary>
		public VwOsobaParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwOsobaParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwOsobaParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwOsobaParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwOsobaParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwOsobaParameterBuilder
} // end namespace
